package digitalmat.p.com.google.code;

public class Grille {
	private static int limite = 10000;
	private int[][] tabGrille;
	
	public Grille() {

		this.tabGrille = new int[limite][limite];
		for (int i = 0; i < limite; i++)
			for (int j = 0; j < limite; j++)			
				this.tabGrille[i][j] = 0;
				
	}

	public int[][] getTabGrille() {
		return tabGrille;
	}

	public void setTabGrille(int[][] tabGrille) {
		this.tabGrille = tabGrille;
	}

	public void deplacerSprite(int x, int y, Sprite laSprite){
		retirerSprite(laSprite);
		deposerSprite(x,y,laSprite);
	}
	public void retirerSprite(Sprite laSpriteRS){
		Forme laFormeRS;
		int taillexRS;
		int posixRS;
		int posiyRS;
		int tailleyRS;
		int valeurRS = 0;
		int[][] tabSpriteRS;
	
		laFormeRS = laSpriteRS.getLaforme();
		tabSpriteRS = laFormeRS.getTab();
		taillexRS = laFormeRS.getTaillex();
		tailleyRS = laFormeRS.getTailley();
		posixRS = laFormeRS.getPosix();
		posiyRS = laFormeRS.getPosiy();
		
		for (int i = posixRS; i < taillexRS; i++)
			for (int j = posiyRS; j < tailleyRS; j++)
				if (tabSpriteRS[i-posixRS][j-posiyRS]==1)	{	
					valeurRS = tabGrille[i][j];
					valeurRS = Liste.retraitElement( laSpriteRS, valeurRS);
					tabGrille[i][j] = valeurRS;
				}
		Liste.nettoyerListe();
	}
	public void deposerSprite(int xDS, int yDS, Sprite laSpriteDS){
		Forme laFormeDS;
		int taillexDS;
		int tailleyDS;
		int posixDS;
		int posiyDS;
		int valeurDS = 0;
		int[][] sousGrille;// doit la garder me je me rappel plus pourquoi.
		int[][] tabSpriteDS;
		
		laFormeDS = laSpriteDS.getLaforme();
		tabSpriteDS = laFormeDS.getTab();
		taillexDS = laFormeDS.getTaillex();
		tailleyDS = laFormeDS.getTailley();
		sousGrille = new int[taillexDS][tailleyDS];
		posixDS = laFormeDS.getPosix();
		posiyDS = laFormeDS.getPosiy();
		
		for (int i = xDS; i < taillexDS; i++)
			for (int j = yDS; j < tailleyDS; j++)	
				if (tabSpriteDS[i-xDS][j-yDS]==1)	{	
					sousGrille[i-xDS][j-yDS] = valeurDS = tabGrille[i][j];
					valeurDS = Liste.ajoutElement( laSpriteDS, valeurDS);
					tabGrille[i][j] = valeurDS;
				}
		
	}
}
